<template>
  <div class="setting">
    <el-form ref="settingForm" label-position="left" label-width="180px">
      <el-form-item label="每日登录失败验证次数：">
        <el-input-number v-model="login_times" size="mini" placeholder="请输入登录次数：" />
      </el-form-item>
      <el-form-item label="登录过期时间限制(小时)：">
        <el-input-number v-model="login_exp_time" size="mini" placeholder="请输入登录过期时间：" />
      </el-form-item>
      <el-form-item label="默认密码：">
        <el-input v-model="reset_pass" size="mini" placeholder="请输入默认密码：" style="width:50%" />
      </el-form-item>
      <el-form-item>
        <el-button size="mini" icon="el-icon-document-checked" type="primary" @click="saveSetting()">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { SaveSetting,SelectSetting } from "@/api/setting/setting";

export default {
  name: "Setting",
  data() {
    return {
      login_times: "",
      login_exp_time: "",
      reset_pass: "",
      settingForm: {}
    };
  },
  created() {
    this.selectSetting();
  },
  methods: {
    //查看设置
    selectSetting() {
      //加载login
      SelectSetting()
        .then(res => {
          if (res.code == 0) {
            console.log(res.data.setting);
            this.login_times = res.data.setting.login_times;
            this.login_exp_time = res.data.setting.login_exp_time;
            this.reset_pass =res.data.setting.reset_pass;
          }
        })
        .catch(err => {});
    },
    //保存设置
    saveSetting() {
      let data = {
        login_times: this.login_times,
        login_exp_time: this.login_exp_time,
        reset_pass: this.reset_pass
      };
      SaveSetting(data)
        .then(res => {
          if (res.code == 0) {
            this.$message({
              message: res.msg,
              type: "success"
            });
            this.getData();
          } else {
            this.$message({
              message: res.msg,
              type: "error"
            });
          }
        })
        .catch(err => {});
    }
  }
};
</script>

<style lang="scss" scoped>
.setting {
  padding: 20px;
  width: 500px;
}
</style>
